package com.qf.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;

/*
 *@Description:
 *@author:刘哥
 *@Date:86180 2022/8/31 11:31
 */
//@RequestMapping("/upload")
//@Controller
//@ResponseBody
@RestController
public class UploadController {

    @RequestMapping(method = RequestMethod.POST,value = "/upload")//限制必须使用post请求
    public String upload(MultipartFile file,String username){
//        设置文件保存路径
        String path="E:/";
        String name=file.getName();
//        获取上传组件的名字
        String originalFilename = file.getOriginalFilename();
        System.out.println(name+"===========>"+originalFilename);

        try {
            file.transferTo(new File(path+originalFilename));
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        return "success";
    }
}
